import commonjs from "@rollup/plugin-commonjs";
import { nodeResolve } from "@rollup/plugin-node-resolve";
import { terser } from "rollup-plugin-terser";
import typescript from "rollup-plugin-typescript2";
import pkg from "./package.json";

function config({ plugins = [], output = {} }) {
  return {
    input: "src/index.ts",
    onwarn: function (warning) {
      if (warning.code === 'THIS_IS_UNDEFINED') {
        return;
      }
    },
    plugins: [
      typescript(),
      nodeResolve(),
      commonjs(),
      ...plugins
    ],
    output: output,
    external: [
      "axios",
      "js-cookie"
    ],
  };
}

export default [
  config({
    plugins: [terser()],
    output: {
      format: "esm",
      file: pkg.module,
      exports: "named",
    },
  }),
  config({
    plugins: [terser()],
    output: {
      format: "umd",
      name: pkg.name,
      file: pkg.unpkg,
      exports: "named",
      globals: {
        axios: "axios",
        "js-cookie": "js-cookie"
      },
    },
  }),
];
